package com.edu.service.impl;

import com.edu.bean.User;
import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Map<String, Object> login(String userName, String password) {
        HashMap<String, Object> result = new HashMap<>();
        User user = userMapper.selectByNameAndPass(userName, password);
        if (user != null) {
            result.put("loginUser", user);
        } else {
            User user1 = userMapper.selectByName(userName);
            if (user1 != null) {
                result.put("msg", "密码错误");
            } else {
                result.put("msg", "账号不存在");
            }
        }
        return result;
    }

    @Override
    public int addUser(User user) {

        return userMapper.insertUser(user);
    }
}
